package com.zhentao.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhentao.pojo.Yuyue;
import com.zhentao.service.YuyueService;
import com.zhentao.mapper.YuyueMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.regex.Pattern;

/**
* @author HP
* @description 针对表【yuyue】的数据库操作Service实现
* @createDate 2025-03-24 10:02:08
*/
@Service
public class YuyueServiceImpl extends ServiceImpl<YuyueMapper, Yuyue> implements YuyueService{

    @Autowired
    private YuyueMapper yuyueMapper;
    @Override
    public String add(Yuyue yuyue) {
        int i = yuyueMapper.insert(yuyue);
        if(i>0){
            return "预约成功";
        }
        return "预约失败";
    }

    /**
     * 校验身份证号是否有效
     * @param idCard 身份证号
     * @return 如果身份证号有效返回true，否则返回false
     */
    public boolean isValidIdCard(String idCard) {
        if (idCard == null || idCard.length() != 18) {
            return false;
        }
        String regex = "^[1-9]\\d{5}(18|19|20)\\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\\d|3[01])\\d{3}[0-9Xx]$";
        Pattern pattern = Pattern.compile(regex);
        return pattern.matcher(idCard).matches();
    }
}




